package com.jtbd.dto.request;

import com.jtbd.domain.Course;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Schema(description = "创建课程的数据类")
@Data
public class CourseItemHttpDto {
    @Schema(description = "课程ID")
    private Long id;
    @Schema(description = "校区ID")
    @NotNull(message = "校区不能为空")
    private Long campusId;
    @NotBlank(message = "课程名称不能为空")
    @Schema(description = "课程名称")
    private String courseName;
    @NotBlank(message = "课程描述不能为空")
    @Schema(description = "课程描述")
    private String courseDesc;
    @NotNull(message = "课程总时长不能为空")
    @Schema(description = "课程总时长")
    @Min(value = 0, message = "课程总时长不能小于0")
    private Integer courseTotalTime;
    @Schema(description = "课程科目ID")
    @NotBlank(message = "课程科目ID不能为空")
    private String courseSubjectIds;
    @Schema(description = "课程科目")
    @NotBlank(message = "课程科目不能为空")
    private String courseSubject;
    @Schema(description = "课程分类")
    private Integer courseCategory;
    @Schema(description = "课程类型")
    @NotNull(message = "课程类型不能为空")
    private Integer courseType;
    @Schema(description = "课程等级")
    @NotNull(message = "课程等级不能为空")
    private Integer courseLevel;
    @Schema(description = "课程价格")
    @NotNull(message = "课程价格不能为空")
    private BigDecimal coursePrice;
    @Schema(description = "课程折扣")
    private BigDecimal courseDiscount;
    @Schema(description = "课程状态 0 - 未开始，1 - 进行中，2 - 已结课")
    private Integer courseStatus;
    @Schema(description = "课程备注")
    private String courseRemark;
    @Schema(description = "课程开始日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "课程开始日期不能为空")
    private Date courseStartDate;
    @Schema(description = "课程结束日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "课程结束日期不能为空")
    private Date courseEndDate;

    /**
     * 将CourseItemHttpDto对象转换为Course对象
     *
     * @param item CourseItemHttpDto对象，包含课程的详细信息
     * @return Course对象，包含转换后的课程信息
     */
    public static Course toCourse(CourseItemHttpDto item) {
        return Course.builder().id(item.id).campusId(item.campusId).courseName(item.courseName).courseDesc(item.courseDesc).courseTotalTime(item.courseTotalTime).courseSubjectIds(item.courseSubjectIds).courseSubject(item.courseSubject).courseCategory(item.courseCategory).courseType(item.courseType).courseLevel(item.courseLevel).coursePrice(item.coursePrice).courseDiscount(item.courseDiscount).courseStartDate(item.courseStartDate).courseEndDate(item.courseEndDate).courseStatus(item.courseStatus).courseRemark(item.courseRemark).build();
    }

}
